package com.lg.partition14;

import java.io.*;
import java.util.Arrays;
import java.util.PriorityQueue;

/**
 * @author `RKC`
 * @date 2022/4/12 9:49
 */
public class P1396营救 {

    private static final int N = 10010, M = 40010, INF = 0x3f3f3f3f;
    private static int[] h = new int[N], e = new int[M], ne = new int[M], w = new int[M];
    private static int[] dist = new int[N];
    private static PriorityQueue<Node> heap = new PriorityQueue<>(N);
    private static int n, m, idx = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        m = Integer.parseInt(ss[1]);
        Arrays.fill(h, -1);
        int s = Integer.parseInt(ss[2]), t = Integer.parseInt(ss[3]), mind = INF, maxd = -INF;
        for (int i = 0; i < m; i++) {
            ss = reader.readLine().split(" ");
            int a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]), c = Integer.parseInt(ss[2]);
            add(a, b, c);
            add(b, a, c);
            mind = Math.min(mind, c);
            maxd = Math.max(maxd, c);
        }
        //最大值最小，考虑二分
        int l = mind, r = maxd;
        while (l < r) {
            int mid = l + r >> 1;
            if (check(s, t, mid)) r = mid;
            else l = mid + 1;
        }
        writer.write(l + "\n");
        writer.flush();
    }

    private static boolean check(int s, int t, int limit) {
        for (int i = 0; i <= n; i++) dist[i] = INF;
        dist[s] = 0;
        heap.add(new Node(s, 0));
        while (!heap.isEmpty()) {
            Node cur = heap.poll();
            int u = cur.u;
            if (u == t) return true;
            for (int i = h[u]; i != -1; i = ne[i]) {
                int v = e[i];
                if (dist[v] > dist[u] + w[i] && w[i] <= limit) {
                    dist[v] = dist[u] + w[i];
                    heap.add(new Node(v, dist[v]));
                }
            }
        }
        return false;
    }

    private static void add(int a, int b, int c) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx;
        w[idx++] = c;
    }

    private static class Node implements Comparable<Node> {
        private int u, d;

        public Node(int u, int d) {
            this.u = u;
            this.d = d;
        }

        @Override
        public int compareTo(Node o) {
            return Integer.compare(d, o.d);
        }
    }
}
